﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpHomeEngine;

namespace Insteon.Requests
{
    public class StartAllLinking : InsteonRequest
    {
        public readonly LinkCode.Codes Code;
        public readonly byte Group;
        public StartAllLinking(Controller Controller, InsteonInterface DeviceInterface, LinkCode.Codes Code, byte Group)
            : base(Controller, DeviceInterface)
        {
            this.Code = Code;
            this.Group = Group;
        }

        internal override void BeginExecute()
        {
            Commands.Command Command = new Commands.Insteon.StartAllLinkCommand(Code, Group);
            Command.InsteonRequest = this;
            InsteonInterface.QueueCommand(Command);
        }

        internal override void CommandCompleted(Commands.Command Command)
        {
            if (Command is Commands.Insteon.StartAllLinkCommand)
            {
                this.Complete(Command.isComplete, Command.isSuccessful);
                TimeSpan Duration = DateTime.Now.Subtract(Command.SentTime).Duration();
                Console.WriteLine("Command {0} {1}  Completed Sucess={2}  Duration {3:0.000}s ", Command.SentTime.ToString("HHmmss.fff"), Command.Number, Command.isSuccessful, (Duration.TotalMilliseconds / 1000));
            }
        }
    }
}
